package com.example.tupu.repository;


import com.example.tupu.entity.Figure;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FigureRepository extends Neo4jRepository<Figure, Long> {
    /**
     * 通过title查找
     * @param title
     * @return
     */
    @Query("MATCH (n:Figure) WHERE n.title =~ ('.*'+$title+'.*') RETURN n")
    Figure findTitle(String title);

    List<Figure> findAllByTitle(String title);

    List<Figure> findAllByTitleLike(String title);

    /**
     * 查询所有关系节点
     * @param limit
     * @return
     */
    @Query("MATCH p=(:Figure {title:$title})-[]->() RETURN p LIMIT $limit")
    List<Figure> getFigure(String title, int limit);

    @Query("MATCH (n:Figure) where n.year > $startyear and n.death < $endyear and n.year<>0 return n")
    List<Figure> getTown(Long startyear,Long endyear);

    @Query("MATCH (n:Figure) where  n.year=0  and n.death <$endyear and n.death <> 0 return n")
    List<Figure> getTownStartNull(Long endyear);
}
